// DingDanOrderController.java
package com.iflytek.springboot_medicine.controller;

import com.iflytek.springboot_medicine.entity.DingDanOrder;
import com.iflytek.springboot_medicine.service.DingDanOrdersService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/dingdan")
@CrossOrigin
public class DingDanOrderController {
    @Resource
    private DingDanOrdersService dingDanOrdersService;

    @GetMapping("/user")
    public Map<String, Object> getOrdersByUserName(@RequestParam String userName) {
        System.out.println("接收到的用户名参数: " + userName);
        Map<String, Object> result = new HashMap<>();
        try {
            List<DingDanOrder> orders = dingDanOrdersService.getOrdersByUserName(userName);
            System.out.println("查询到的订单数据: " + orders);
            System.out.println("订单数量: " + (orders != null ? orders.size() : 0));
            
            result.put("code", 200);
            result.put("data", orders);
            result.put("message", "success");
            
            System.out.println("返回的结果: " + result);
        } catch (Exception e) {
            System.out.println("发生错误: " + e.getMessage());
            e.printStackTrace();
            result.put("code", 500);
            result.put("message", e.getMessage());
        }
        return result;
    }
}